package com.leet.code.lcof;

public class Code14_1 {

    public static void main(String[] args) {
//        System.out.println(Math.pow(3, 3));
        int i = new Code14_1().cuttingRope(58);
        System.out.println(i);
    }

    public int cuttingRope(int n) {

        if (n <= 3) {
            return n - 1;
        }

        int s = n / 3;
        int y = n % 3;

        if (y == 0) {
            return (int) Math.pow(3, s);
        } else if (y == 1) {
            return (int) (Math.pow(3, s - 1) * 4);
        }

        return (int) (Math.pow(3, s) * 2);

    }

}
